package lmf;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class ArtistLFM {

	public String name;
	public String mbid;
	public String last_fm_url;
	public String image_small;
	public String image_medium;
	public String image_large;
	public String image_extralarge;
	public String image_mega;
	public String listeners;
	public String playcount;
	public String summary;
	public String bio;

	public ArtistLFM(Document doc) {
		try {
			name = doc.getElementsByTagName("name").item(0).getFirstChild()
					.getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			mbid = doc.getElementsByTagName("mbid").item(0).getFirstChild()
					.getNodeValue();
		}

		catch (Exception e) {
			// TODO: handle exception
		}
		try {
			last_fm_url = doc.getElementsByTagName("url").item(0)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			image_small = doc.getElementsByTagName("image").item(0)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			image_medium = doc.getElementsByTagName("image").item(1)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			image_large = doc.getElementsByTagName("image").item(2)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			image_extralarge = doc.getElementsByTagName("image").item(3)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			image_mega = doc.getElementsByTagName("image").item(4)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			listeners = doc.getElementsByTagName("listeners").item(0)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			playcount = doc.getElementsByTagName("playcount").item(0)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			summary = doc.getElementsByTagName("summary").item(0)
					.getFirstChild().getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
		try {
			bio = doc.getElementsByTagName("content").item(0).getFirstChild()
					.getNodeValue();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	public ArtistLFM(Node node) {
		if (node.getNodeType() == Node.ELEMENT_NODE) {
			Element element = (Element) node;
			name = element.getElementsByTagName("name").item(0).getFirstChild()
					.getNodeValue();
			try {
				mbid = element.getElementsByTagName("mbid").item(0)
						.getFirstChild().getNodeValue();
			} catch (Exception e) {
				// e.printStackTrace();
				// means artist doesnt have an mbid
			}
			playcount = element.getElementsByTagName("playcount").item(0)
					.getFirstChild().getNodeValue();
			last_fm_url = element.getElementsByTagName("url").item(0)
					.getFirstChild().getNodeValue();
			image_small = element.getElementsByTagName("image").item(0)
					.getFirstChild().getNodeValue();
			image_medium = element.getElementsByTagName("image").item(1)
					.getFirstChild().getNodeValue();
			image_large = element.getElementsByTagName("image").item(2)
					.getFirstChild().getNodeValue();
			image_extralarge = element.getElementsByTagName("image").item(3)
					.getFirstChild().getNodeValue();
			image_mega = element.getElementsByTagName("image").item(4)
					.getFirstChild().getNodeValue();

		}
	}
}

/*
 * 
 * <artist> <name>The Beatles</name>
 * <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid>
 * <url>http://www.last.fm/music/The+Beatles</url> <image
 * size="small">http://userserve-ak.last.fm/serve/34/10979431.jpg</image> <image
 * size="medium">http://userserve-ak.last.fm/serve/64/10979431.jpg</image>
 * <image
 * size="large">http://userserve-ak.last.fm/serve/126/10979431.jpg</image>
 * <image
 * size="extralarge">http://userserve-ak.last.fm/serve/252/10979431.jpg</image>
 * <image
 * size="mega">http://userserve-ak.last.fm/serve/500/10979431/The+Beatles+
 * fun.jpg</image> <streamable>1</streamable> <stats>
 * <listeners>2633415</listeners> <playcount>342642895</playcount> </stats>
 */